package locations.dao.implement;

import java.util.List;
import javax.persistence.criteria.CriteriaQuery;
import locations.dao.PacientDAO;
import locations.model.Pacient;


public class PacientDAOHibernateJPA extends GenericDAOHibernateJPA<Pacient> implements PacientDAO
{

	public PacientDAOHibernateJPA()
        {
		super(Pacient.class);
	}
        
        public boolean exists(String dni, long id)
        {
            boolean started = this.getTransaction().isActive();
            if (!started)
            {
                this.getTransaction().begin();            
            }
            String queryId = (id == 0 ? "" :  " and p.id !='" + id + "'");
            List result= entityManager.createQuery
                    ("from Pacient p where p.documento='" + dni + "'" + queryId).getResultList();
            this.getTransaction().commit();            
            return ! result.isEmpty();
        }

}
